/*     */ package com.wgcloud.controller;
/*     */ 
/*     */ import cn.hutool.json.JSONObject;
/*     */ import cn.hutool.json.JSONUtil;
/*     */ import com.github.pagehelper.PageInfo;
/*     */ import com.wgcloud.entity.DbInfo;
/*     */ import com.wgcloud.entity.DbTable;
/*     */ import com.wgcloud.entity.DbTableCount;
/*     */ import com.wgcloud.service.DashboardService;
/*     */ import com.wgcloud.service.DbInfoService;
/*     */ import com.wgcloud.service.DbTableCountService;
/*     */ import com.wgcloud.service.DbTableService;
/*     */ import com.wgcloud.service.ExcelExportService;
/*     */ import com.wgcloud.service.LogInfoService;
/*     */ import com.wgcloud.util.FormatUtil;
/*     */ import com.wgcloud.util.PageUtil;
/*     */ import com.wgcloud.util.ResDataUtils;
/*     */ import com.wgcloud.util.TokenUtils;
/*     */ import com.wgcloud.util.license.LicenseUtil;
/*     */ import com.wgcloud.util.staticvar.StaticKeys;
/*     */ import java.util.HashMap;
/*     */ import java.util.List;
/*     */ import java.util.Map;
/*     */ import javax.annotation.Resource;
/*     */ import javax.servlet.http.HttpServletRequest;
/*     */ import javax.servlet.http.HttpServletResponse;
/*     */ import org.apache.commons.lang3.StringUtils;
/*     */ import org.slf4j.Logger;
/*     */ import org.slf4j.LoggerFactory;
/*     */ import org.springframework.beans.factory.annotation.Autowired;
/*     */ import org.springframework.stereotype.Controller;
/*     */ import org.springframework.ui.Model;
/*     */ import org.springframework.web.bind.annotation.RequestBody;
/*     */ import org.springframework.web.bind.annotation.RequestMapping;
/*     */ import org.springframework.web.bind.annotation.ResponseBody;
/*     */ import org.springframework.web.servlet.mvc.support.RedirectAttributes;
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ @Controller
/*     */ @RequestMapping({"/dbTable"})
/*     */ public class DbTableController
/*     */ {
/*  47 */   private static final Logger logger = LoggerFactory.getLogger(com.wgcloud.controller.DbTableController.class);
/*     */ 
/*     */   
/*     */   @Resource
/*     */   private DbInfoService dbInfoService;
/*     */   
/*     */   @Resource
/*     */   private DbTableService dbTableService;
/*     */   
/*     */   @Resource
/*     */   private DbTableCountService dbTableCountService;
/*     */   
/*     */   @Resource
/*     */   private LogInfoService logInfoService;
/*     */   
/*     */   @Resource
/*     */   private DashboardService dashboardService;
/*     */   
/*     */   @Autowired
/*     */   private TokenUtils tokenUtils;
/*     */   
/*     */   @Resource
/*     */   private ExcelExportService excelExportService;
/*     */ 
/*     */   
/*     */   @ResponseBody
/*     */   @RequestMapping({"agentList"})
/*     */   public String agentList(@RequestBody String paramBean) {
/*  75 */     if (!StaticKeys.LICENSE_STATE.equals("1")) {
/*  76 */       return ResDataUtils.resetErrorJson("请先升级到专业版");
/*     */     }
/*  78 */     JSONObject agentJsonObject = (JSONObject)JSONUtil.parse(paramBean);
/*  79 */     if (!this.tokenUtils.checkAgentToken(agentJsonObject)) {
/*  80 */       logger.error("token is error");
/*  81 */       return ResDataUtils.resetErrorJson("token is error");
/*     */     } 
/*  83 */     Map<String, Object> params = new HashMap<>();
/*     */     try {
/*  85 */       params.put("active", "1");
/*  86 */       List<DbTable> DockerInfoList = this.dbTableService.selectAllByParams(params);
/*  87 */       return ResDataUtils.resetSuccessJson(DockerInfoList);
/*  88 */     } catch (Exception e) {
/*  89 */       logger.error("agent获取监控数据表信息错误", e);
/*  90 */       this.logInfoService.save("agent获取监控数据表信息错误", e.toString(), "1");
/*  91 */       return ResDataUtils.resetErrorJson(e.toString());
/*     */     } 
/*     */   }
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */   
/*     */   @RequestMapping({"list"})
/*     */   public String DbTableList(DbTable dbTable, Model model, HttpServletRequest request) {
/* 104 */     Map<String, Object> params = new HashMap<>();
/*     */     
/*     */     try {
/* 107 */       LicenseUtil.maxLicense_10(model, request);
/*     */ 
/*     */       
/* 110 */       StringBuffer url = new StringBuffer();
/* 111 */       String dbInfoId = null;
/* 112 */       if (!StringUtils.isEmpty(dbTable.getDbInfoId())) {
/* 113 */         dbInfoId = dbTable.getDbInfoId();
/* 114 */         params.put("dbInfoId", dbInfoId.trim());
/* 115 */         url.append("&dbInfoId=").append(dbInfoId);
/*     */       } 
/*     */ 
/*     */       
/* 119 */       PageInfo<DbTable> pageInfo = this.dbTableService.selectByParams(params, dbTable.getPage().intValue(), dbTable.getPageSize().intValue());
/* 120 */       PageUtil.initPageNumber(pageInfo, model);
/* 121 */       params.clear();
/* 122 */       List<DbInfo> dbInfoList = this.dbInfoService.selectAllByParams(params);
/* 123 */       for (DbTable dbTable1 : pageInfo.getList()) {
/* 124 */         for (DbInfo dbInfo : dbInfoList) {
/* 125 */           if (dbInfo.getId().equals(dbTable1.getDbInfoId())) {
/* 126 */             dbTable1.setTableName(dbInfo.getAliasName());
/*     */           }
/*     */         } 
/*     */       } 
/* 130 */       model.addAttribute("pageUrl", "/dbTable/list?1=1" + url.toString());
/* 131 */       model.addAttribute("page", pageInfo);
/* 132 */       model.addAttribute("dbTable", dbTable);
/* 133 */       model.addAttribute("dbInfoList", dbInfoList);
/* 134 */     } catch (Exception e) {
/* 135 */       logger.error("查询数据表信息错误", e);
/* 136 */       this.logInfoService.save("查询数据表信息错误", e.toString(), "1");
/*     */     } 
/*     */     
/* 139 */     return "mysql/tableList";
/*     */   }
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */   
/*     */   @RequestMapping({"save"})
/*     */   public String saveDbTable(DbTable dbTable, Model model, HttpServletRequest request) {
/*     */     try {
/* 156 */       String sqlinkey = FormatUtil.haveSqlDanger(dbTable.getWhereVal());
/* 157 */       if (!StringUtils.isEmpty(sqlinkey)) {
/* 158 */         model.addAttribute("dbTable", dbTable);
/* 159 */         List<DbInfo> dbInfoList = this.dbInfoService.selectAllByParams(new HashMap<>());
/* 160 */         model.addAttribute("dbInfoList", dbInfoList);
/* 161 */         model.addAttribute("msg", "统计SQL语句含有sql敏感字符" + sqlinkey + "，请检查");
/* 162 */         return "mysql/addTable";
/*     */       } 
/*     */ 
/*     */       
/* 166 */       if (StringUtils.isEmpty(dbTable.getId())) {
/* 167 */         this.dbTableService.save(dbTable);
/*     */       } else {
/* 169 */         this.dbTableService.updateById(dbTable);
/*     */       } 
/* 171 */     } catch (Exception e) {
/* 172 */       logger.error("保存数据表错误", e);
/* 173 */       this.logInfoService.save("保存数据表错误", e.toString(), "1");
/*     */     } 
/* 175 */     return "redirect:/dbTable/list";
/*     */   }
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */   
/*     */   @RequestMapping({"edit"})
/*     */   public String editDbTable(DbTable dbTable, Model model, HttpServletRequest request) {
/*     */     try {
/* 190 */       String id = request.getParameter("id");
/* 191 */       DbTable dbTableInfo = new DbTable();
/* 192 */       if (!StringUtils.isEmpty(id)) {
/* 193 */         dbTableInfo = this.dbTableService.selectById(id);
/*     */       }
/*     */ 
/*     */       
/* 197 */       Map<String, Object> params = new HashMap<>();
/* 198 */       int dbSize = this.dbTableService.countByParams(params);
/* 199 */       if (dbSize >= 10 && !StaticKeys.LICENSE_STATE.equals("1")) {
/* 200 */         return "redirect:/dbTable/list?liceFlage=1";
/*     */       }
/*     */ 
/*     */       
/* 204 */       List<DbInfo> dbInfoList = this.dbInfoService.selectAllByParams(new HashMap<>());
/* 205 */       model.addAttribute("dbInfoList", dbInfoList);
/* 206 */       model.addAttribute("dbTable", dbTableInfo);
/* 207 */     } catch (Exception e) {
/* 208 */       logger.error("查看数据表错误", e);
/* 209 */       this.logInfoService.save("查看数据表错误", e.toString(), "1");
/*     */     } 
/* 211 */     return "mysql/addTable";
/*     */   }
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */   
/*     */   @RequestMapping({"viewChart"})
/*     */   public String viewChartDbTable(DbTable dbTable, Model model, HttpServletRequest request) {
/*     */     try {
/* 225 */       String id = request.getParameter("id");
/* 226 */       if (!StringUtils.isEmpty(id)) {
/* 227 */         DbTable dbTableInfo = this.dbTableService.selectById(id);
/* 228 */         Map<String, Object> params = new HashMap<>();
/*     */         
/* 230 */         params.put("dbTableId", id);
/* 231 */         List<DbTableCount> dbTableCounts = this.dbTableCountService.selectAllByParams(params);
/* 232 */         model.addAttribute("dbTableCounts", JSONUtil.parseArray(dbTableCounts));
/* 233 */         model.addAttribute("dbTable", dbTableInfo);
/*     */       } 
/* 235 */     } catch (Exception e) {
/* 236 */       logger.error("查看数据表图表统计错误", e);
/* 237 */       this.logInfoService.save("查看数据表图表统计错误", e.toString(), "1");
/*     */     } 
/* 239 */     return "mysql/tableView";
/*     */   }
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */   
/*     */   @RequestMapping({"chartExcel"})
/*     */   public void chartExcel(Model model, HttpServletRequest request, HttpServletResponse response) {
/* 251 */     String errorMsg = "数据表统计图导出excel错误";
/* 252 */     String id = request.getParameter("id");
/*     */     try {
/* 254 */       if (!StaticKeys.LICENSE_STATE.equals("1")) {
/* 255 */         response.setContentType("text/html;charset=UTF-8");
/* 256 */         response.getOutputStream().write("The excel needs to wgcloud-pro version".getBytes());
/*     */         return;
/*     */       } 
/* 259 */       if (StringUtils.isEmpty(id)) {
/* 260 */         response.setContentType("text/html;charset=UTF-8");
/* 261 */         response.getOutputStream().write("The excel must  require parameters".getBytes());
/*     */         return;
/*     */       } 
/* 264 */       Map<String, Object> params = new HashMap<>();
/* 265 */       params.put("dbTableId", id);
/* 266 */       this.excelExportService.exportDbTableExcel(params, response);
/* 267 */     } catch (Exception e) {
/* 268 */       logger.error(errorMsg, e);
/* 269 */       this.logInfoService.save(errorMsg, e.toString(), "1");
/*     */     } 
/*     */   }
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */   
/*     */   @RequestMapping({"del"})
/*     */   public String delete(Model model, HttpServletRequest request, RedirectAttributes redirectAttributes) {
/* 285 */     String errorMsg = "删除数据表信息错误";
/*     */     try {
/* 287 */       if (!StringUtils.isEmpty(request.getParameter("id"))) {
/* 288 */         String[] ids = request.getParameter("id").split(",");
/* 289 */         for (String id : ids) {
/* 290 */           DbTable dbTable = this.dbTableService.selectById(id);
/* 291 */           this.logInfoService.save("删除数据表：" + dbTable.getRemark(), "删除数据表：" + dbTable.getRemark(), "0");
/*     */         } 
/* 293 */         this.dbTableService.deleteById(ids);
/*     */       } 
/* 295 */     } catch (Exception e) {
/* 296 */       logger.error(errorMsg, e);
/* 297 */       this.logInfoService.save(errorMsg, e.toString(), "1");
/*     */     } 
/*     */     
/* 300 */     return "redirect:/dbTable/list";
/*     */   }
/*     */ }


/* Location:              /Users/zhangyongxin/soft-install/wgcloud/wgcloud-v3.3.5/server/bank/wgcloud-server-release.jar!/BOOT-INF/classes/com/wgcloud/controller/DbTableController.class
 * Java compiler version: 8 (52.0)
 * JD-Core Version:       1.1.3
 */